﻿using Ease.EaseMission.Runtime;
using Ease.EaseNode.Runtime;
using UnityEngine.UIElements;

namespace Ease.EaseMission.Editor.Node
{
    public class MissionDataNode : BaseMissionNode<MissionData>
    {
        private Label titleLabel;
        private StyleColor titleLabelInitColor;

        public MissionDataNode(IEaseNodeDataState state) : base(state)
        {
            titleLabel = contentContainer.Q<Label>("title-label", (string) null);
            titleLabelInitColor = titleLabel.style.backgroundColor;
            if (missionData != null)
                titleLabel.style.backgroundColor = string.IsNullOrEmpty(missionData.Name) ? NodeVisual.TitleError : titleLabelInitColor;
            else
                titleLabel.style.backgroundColor = titleLabelInitColor;
        }

        protected override void OnRefreshAll()
        {
            base.OnRefreshAll();
            if (missionData != null)
                titleLabel.style.backgroundColor = string.IsNullOrEmpty(missionData.Name) ? NodeVisual.TitleError : titleLabelInitColor;
            else
                titleLabel.style.backgroundColor = titleLabelInitColor;
        }
        
    }
}